package com.hxrfid.demo.controller;

import com.hxrfid.common.core.domain.R;
import com.hxrfid.sms.entity.SmsResult;
import com.hxrfid.sms.util.SmsUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 短信演示案例
 * 请先阅读文档 否则无法使用
 *
 * @author Lion Li
 * @version 4.2.0
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/demo/sms")
public class SmsController {

    /**
     * 发送短信
     *
     * @param phones     电话号
     * @param templateId 模板ID
     */
    @GetMapping("/sendSms")
    public R<Object> sendSms(String phones, String templateId) {
        Map<String, String> map = new HashMap<>(1);
        map.put("code", "1234");
        SmsResult result = SmsUtil.send(phones, templateId, map);
        if (!result.getIsSuccess()) {
            return R.fail(result.getMessage());
        }
        return R.ok(result);
    }

}
